use sqlx::PgPool;

use crate::{db, filter, model, Error, Result};

pub async fn find<'a>(
    p: &PgPool,
    f: &filter::user_url::FindBy<'a>,
) -> Result<Option<model::user_url::UserUrl>> {
    db::user_url::find(p, f).await.map_err(Error::from)
}

pub async fn list<'a>(
    p: &PgPool,
    f: &filter::user_url::List<'a>,
) -> Result<db::Pagination<model::user_url::UserUrl>> {
    let total = db::user_url::list_count(p, f).await.map_err(Error::from)?;
    let data = db::user_url::list_data(p, f).await.map_err(Error::from)?;
    Ok(db::Pagination::quick(total, &f.pagination, data))
}
